package me.jessyan.mvparms.demo.di.module.shoppcard;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.CustomPopupWindow;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.contract.shoppcard.CardDetailContract;
import me.jessyan.mvparms.demo.mvp.model.shoppcard.CardDetailModel;
import me.jessyan.mvparms.demo.mvp.ui.widget.BubbleView;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;


@Module
public class CardDetailModule {
    private CardDetailContract.View view;

    /**
     * 构建CardDetailModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public CardDetailModule(CardDetailContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    CardDetailContract.View provideCardDetailView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    CardDetailContract.Model provideCardDetailModel(CardDetailModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    @Named("unbindPop")
    CustomPopupWindow unbindPop(){
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_gift_detail_delete,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .defultHeight(ArmsUtils.dip2px(view.getActivity().getApplication(),56))

                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {

                        BubbleView bubbleView = contentView.findViewById(R.id.delete_tv);
                        bubbleView.setText("解绑");
                        bubbleView.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {

                                view.dismissPop();
                                view.popBackUnbind();
                            }
                        });
                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }
}